package amend;

import com.lijinjiang.beautyeye.BeautyEyeLNFHelper;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;

/**
 * @ClassName Amend08_JSplitPane
 * @Description 调整 JSplitPane 的 UI
 * @Author Li
 * @Date 2022/8/30 17:20
 * @ModifyDate 2022/8/30 17:20
 * @Version 1.0
 */
public class Amend08_JSplitPane {
    public static void main(String[] args) {
        try {
            /**
             * 设置本属性将改变窗口边框样式定义
             * 系统默认样式 : osLookAndFeelDecorated
             * 强立体半透明 : translucencyAppleLike
             * 弱立体半透明 : translucencySmallShadow
             * 普通不透明 : generalNoTranslucencyShadow
             */
            BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.generalNoTranslucencyShadow;
            BeautyEyeLNFHelper.launchBeautyEyeLNF();
        } catch (Exception e) {
            e.printStackTrace();
        }
        JFrame frame = new JFrame(); // 初始化窗口
        frame.setTitle("Amend08"); // 设置标题

        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, createTree(), createTextArea());
        splitPane.setDividerSize(3);
        splitPane.setDividerLocation(150); // 设置分隔线的的位置
        splitPane.setBorder(null);
        frame.add(splitPane);

        frame.setSize(new Dimension(800, 600)); // 显示大小
        frame.setLocationRelativeTo(null); // 屏幕居中
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置默认关闭方式
        frame.setVisible(true);

    }

    private static JScrollPane createTree() {
        JScrollPane scrollPane = new JScrollPane();
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("中国");
        String Areas[][] = new String[3][];
        Areas[0] = new String[]{"北京", "上海", "广州", "深圳"};
        Areas[1] = new String[]{"杭州", "南京", "济南", "重庆"};
        Areas[2] = new String[]{"荆州", "唐山", "温州", "嘉兴"};
        String gradeNames[] = {"一线城市", "二线城市", "三线城市"};
        DefaultMutableTreeNode node = null;
        DefaultMutableTreeNode childNode = null;
        int length = 0;
        for (int i = 0; i < 3; i++) {
            length = Areas[i].length;
            node = new DefaultMutableTreeNode(gradeNames[i]);
            for (int j = 0; j < length; j++) {
                childNode = new DefaultMutableTreeNode(Areas[i][j]);
                node.add(childNode);
            }
            root.add(node);
        }
        JTree tree = new JTree(root);
        tree.setRowHeight(30);
        tree.setShowsRootHandles(true);//是否显示句柄
        scrollPane.add(tree);
        scrollPane.setViewportView(tree);
        tree.setRootVisible(false);
        scrollPane.setVisible(true);
        scrollPane.setBorder(null);
        return scrollPane;
    }

    private static JScrollPane createTextArea() {
        JTextArea textArea = new JTextArea();
        JScrollPane scrollPane = new JScrollPane(textArea);
        scrollPane.setBorder(null);
        return scrollPane;
    }
}
